Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Account for inaccurate offsets in getXrefData() #692

Merged
merged 3 commits into from
Apr 2, 2024

Conversation

GreyWyvern
Copy link
Contributor

@GreyWyvern GreyWyvern commented Mar 14, 2024

Type of pull request

  • Bug fix (involves code and configuration changes)

About

Normally offset pointers to xref keywords in a PDF document are exact to the byte. However, in some cases the pointer may point to some whitespace before the xref keyword. Adobe Acrobat takes these 'errors' in stride, displaying the document anyway, and so should PdfParser.

Clean up the getXrefData() function in RawDataParser.php. It now only needs to do one preg_match_all() and pushes the caret past whitespace when looking for xref keywords.

Use existing Issue557.pdf to create a new file: Issue673.pdf where the last /Prev 13486 command has been decremented to /Prev 13485. Trying to parse this file would cause an Exception without this fix. Resolves #673.

Checklist for code / configuration changes

In case you changed the code/configuration, please read each of the following checkboxes as they contain valuable information:

  • Please add at least one test case (unit test, system test, ...) to demonstrate that the change is working. If existing code was changed, your tests cover these code parts as well.
  • Please run PHP-CS-Fixer before committing, to confirm with our coding styles. See https://github.com/smalot/pdfparser/blob/master/.php-cs-fixer.php for more information about our coding styles.
  • In case you fix an existing issue, please do one of the following:
    • Write in this text something like fixes #1234 to outline that you are providing a fix for the issue #1234.

Normally offset pointers to `xref` keywords in a PDF document are exact to the byte. However, in some cases the pointer may point to some whitespace *before* the `xref` keyword. Adobe Acrobat takes these 'errors' in stride, displaying the document anyway, and so should PdfParser.

Clean up the getXrefData() function in **RawDataParser.php**. It now only needs to do one `preg_match_all()` and pushes the caret past whitespace when looking for `xref` keywords.

Use existing **Issue557.pdf** to create a new file: **Issue673.pdf** where the last `/Prev 13486` command has been decremented to `/Prev 13485`. Trying to parse this file would cause an Exception without this fix.
@k00ni k00ni added the fix label Mar 25, 2024
Copy link
Collaborator

@k00ni k00ni left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you @GreyWyvern, good work! I have just a few remarks/questions.

Copy link
Collaborator

@k00ni k00ni left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for the delay. I merged in a recent change to get rid of the coding style issue.

@k00ni k00ni merged commit fb77eab into smalot:master Apr 2, 2024
29 checks passed
@GreyWyvern GreyWyvern deleted the xref-offset branch May 10, 2024 15:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Undefined array key 1,crash on parsing
2 participants